import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [{
		path: '/login',
		name: 'Login',
		component: () => import('@/views/login/login.vue')
	},
	{
		path: '/',
		name: 'Layout',
		component: () => import('@/components/Layout.vue'),
		redirect: '/home',
		children: [{
				path: "/home",
				name: "Home",
				component: () => import('@/views/tabbar/home.vue'),
				meta: {
					showTabbar: true
				}
			},
			{
				path: '/approval',
				name: 'Approval',
				component: () => import('@/views/tabbar/approval.vue'),
				meta: {
					showTabbar: true
				}
			},
			{
				path: '/mine',
				name: 'Mine',
				component: () => import('@/views/tabbar/mine.vue'),
				meta: {
					showTabbar: true
				}
			},
		]
	},
	{
		path: '/purchaseControl',
		name: 'purchaseControl',
		component: () => import('@/views/purchaseControl/index.vue'),
	},
	{
		path: '/purchase',
		name: 'purchase',
		component: () => import('@/views/purchase/index.vue'),
	},
	{
		path: '/purchase',
		name: 'purchase',
		component: () => import('@/views/purchase/index.vue'),
	},
	{
		path: '/purchaseControlDetail',
		name: 'purchaseControlDetail',
		component: () => import('@/views/purchaseControlDetail/index.vue'),
	},
	{
		path: '/mineInfo',
		name: 'mineInfo',
		component: () => import('@/views/mineInfo/index.vue'),
		meta: {
			showTabbar: true
		}
	},
	{
		path: '/changePassword',
		name: 'changePassword',
		component: () => import('@/views/changePassword/index.vue'),
		meta: {
			showTabbar: true
		}
	},
	{
		path: '/feedback',
		name: 'feedback',
		component: () => import('@/views/feedback/index.vue'),
		meta: {
			showTabbar: true
		}
	},
	{
		path: '/annunciate',
		name: 'annunciate',
		component: () => import('@/views/annunciate/index.vue'),
		meta: {
			showTabbar: true
		}
	},
	{
		path: '/annunciateAdd',
		name: 'annunciateAdd',
		component: () => import('@/views/annunciateAdd/index.vue'),
		meta: {
			showTabbar: true
		}
	},
	{
		path: '/annunciateDetail',
		name: 'annunciateDetail',
		component: () => import('@/views/annunciateDetail/index.vue'),
		meta: {
			showTabbar: true
		}
	},
	{
		path: '/annunciateReadLog',
		name: 'annunciateReadLog',
		component: () => import('@/views/annunciateReadLog/index.vue'),
		meta: {
			showTabbar: true
		}
	},
	{
		path: '/message/index',
		name: 'message',
		component: () => import('@/views/message/index.vue'),
		meta: {
			showTabbar: true
		}
	},
	{
		path: '/messageDetail',
		name: 'messageDetail',
		component: () => import('@/views/messageDetail/index.vue'),
		meta: {
			showTabbar: true
		}
	},
	{
		path: '/myApply',
		name: 'myApply',
		component: () => import('@/views/myApply/index.vue'),
		meta: {
			showTabbar: true
		}
	},
	{
		path: '/myApproval/index',
		name: 'myApproval',
		component: () => import('@/views/myApproval/index.vue'),
		meta: {
			showTabbar: true
		}
	},
	{
		path: '/dispatchRecord',
		name: 'DispatchRecord',
		component: () => import('../staticPages/dispatchRecord/index.vue')
	},
	{
		path: '/carDispatchDetail',
		name: 'CarDispatchDetail',
		component: () => import('../staticPages/carDispatchDetail/index.vue')
	},
	{
		path: '/driverStatistics',
		name: 'DriverStatistics',
		component: () => import('../staticPages/driverStatistics/index.vue')
	},
	{
		path: '/driverDuty',
		name: 'DriverDuty',
		component: () => import('../staticPages/driverDuty/index.vue')
	},
	{
		path: '/useCarRecord',
		name: 'UseCarRecord',
		component: () => import('../staticPages/useCarRecord/index.vue')
	},
	{
		path: '/driverSupervisionList',
		name: 'DriverSupervisionList',
		component: () => import('../staticPages/driverSupervisionList/index.vue')
	},
	{
		path: '/driverSupervision',
		name: 'DriverSupervision',
		component: () => import('../staticPages/driverSupervision/index.vue')
	},
	{
		path: '/carApply',
		name: 'CarApply',
		component: () => import('../staticPages/carApply/index.vue')
	},
	{
		path: '/carApplyOne',
		name: 'CarApplyOne',
		component: () => import('../staticPages/carApplyOne/index.vue')
	},
	{
		path: '/carApplyTwo',
		name: 'CarApplyTwo',
		component: () => import('../staticPages/carApplyTwo/index.vue')
	},
	{
		path: '/numberLimitRule',
		name: 'NumberLimitRule',
		component: () => import('../staticPages/numberLimitRule/index.vue')
	},
	{
		path: '/numberLimitRuleList',
		name: 'NumberLimitRuleList',
		component: () => import('../staticPages/numberLimitRuleList/index.vue')
	},
	{
		path: '/:pathMatch(.*)*',
		name: 'NotFound',
		component: () => import('@/views/404.vue') // 需要创建这个组件
	}
]

const router = new VueRouter({
	routes
})

router.beforeEach((to, from, next) => {

	const user = localStorage.getItem('user')

	// 判断是否是直接在地址栏输入（首次访问或刷新页面）
	// 路由守卫先注释了！！！！
	// if (!user && to.path !== '/login') {
	// 	next('/login')
	// 	return
	// }

	next()
})

export default router